<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .a {
            width: 100%;
            height: auto;
            position: relative;
        }

        #main {
            width: 800px;
            height: 800px;
            margin: auto;
            border: 1px solid violet;
        }
    </style>
</head>

<body>
    <div class="a">
        <div id="main"></div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js"></script>
    <script type="text/javascript">
        var zhu = echarts.init(document.getElementById('main'));
        function fv() {
            var xhr = new XMLHttpRequest()
            xhr.open('get', 'https://liu.zzgoodqc.cn/goodsx/goodslist')
            xhr.send()
            xhr.responseType = 'json'
            xhr.onload = () => {
                var a = []
                var b = []
                xhr.response.data.forEach(item => {

                    a.push(item.goods_name)
                    b.push(item.sold)
                    option = {
                        title: {
                            text: '柱状图'
                        },
                        tooltip: {},
                        legend: {
                            data: '销量'
                        },
                        xAxis: {
                            // type: 'category',
                            data: a
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [
                            {
                                data: b,
                                type: 'bar',
                                name: '销量'
                            }
                        ]
                    };

                    zhu.setOption(option);

                })
            }
            xhr.onerror = (e) => {
                console.log(e);

            }
        }
        fv()
    </script>
</body>

</html>